#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;

int main() {
    // Set random seed
    /*srand(0);

    // Download and load image
    std::string img_path = "imagenet_cat.png";
    cv::Mat resized_image;
    cv::Mat img_data;

    // Download image and resize to 224x224
    cv::Mat img = cv::imread(img_path);
    cv::resize(img, resized_image, cv::Size(224, 224));
      
    // Convert image data to float32
    resized_image.convertTo(img_data, CV_32F);
    std::cout << "Image data shape: " << img_data.size() << std::endl;
    
    std::cout << img_data.at<float>(0, 0) << std::endl;

    // Transpose image data (CHW layout)
    cv::transpose(img_data, img_data);

    std::cout << "Transposed image data shape: " << img_data.size() << std::endl;
    */

    // 图片路径
    std::string img_path = "imagenet_cat.png";

    // 读取图片
    cv::Mat img = cv::imread(img_path);
    cv::Mat resized_image;
    cv::Mat img_data;

    if (img.empty()) {
        std::cerr << "Failed to read the image." << std::endl;
        return -1;
    }

    // 调整大小为 (224, 224)
    cv::resize(img, resized_image, cv::Size(224, 224));

    // Convert image data to float32
    resized_image.convertTo(img_data, CV_32F);

    // Transpose array from HWC layout to CHW layout
    cv::Mat transposed_data;
    cv::transpose(img_data, transposed_data);

    // Display dimensions
    // std::cout << "Transposed data dimensions: " << transposed_data.size() << std::endl;
    //std::cout << "Transposed data at (0, 0): " << transposed_data.at<cv::Vec3f>(0, 0)[0] << std::endl;


    // 打印图片信息
    std::cout << "Image shape: " << img_data.size() << std::endl;

    // 打印第一通道第一个像素点的值
    std::cout << "Value of the first pixel in channel 0: " << std::endl;
    for(int i = 0; i < 224; i++){
    	float pixel_value = (img_data.at<cv::Vec3f>(0, i)[0]);
    	std::cout << pixel_value  << " " ;
    }
    std::cout << "---------------------" << endl;

    std::cout << "Value of the first pixel in channel 1: " << std::endl;    
       for(int i = 0; i < 224; i++){
        float pixel_value = (img_data.at<cv::Vec3f>(0, i)[1]);
        std::cout << pixel_value  << " " ;
    }
    std::cout << "---------------------" << endl;

    std::cout << "Value of the first pixel in channel 2: " << std::endl;
       for(int i = 0; i < 224; i++){
        float pixel_value = (img_data.at<cv::Vec3f>(0, i)[2]);
	std::cout << pixel_value  << " " ;
       }
    std::cout << "---------------------" << endl
	    
	    
   // guiyihua
           	    
   	    

    return 0;
}

